package org.swidgets.base.sbutton;

import org.swidgets.base.BorderStyleRepository;
import org.swidgets.base.spanels.SlimPanel;

import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.FocusWidget;
import com.google.gwt.user.client.ui.Widget;

 class RichButton extends FocusWidget {
	private SlimPanel buttonBorder = new SlimPanel(BorderStyleRepository.button, "ButtonContentOver", "ButtonContentClicked");
		
	public RichButton(String caption) {		  
		this();
		setText(caption);		
	}
	
	public RichButton() {
		super();			
		super.setElement(buttonBorder.getElement());		
						
		sinkEvents(Event.ONMOUSEDOWN | Event.ONMOUSEUP | Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONCLICK);				
	}
	
	public RichButton(Widget w) {
		this();
		buttonBorder.add(w);
	}
	
	public RichButton(String caption,ClickListener listener){
		this();
		setText(caption);
		this.addClickListener(listener);
	}
	
	public void setText(String html) {
		buttonBorder.setHtml(html);
	}	 

	static native void click(Element button) /*-{
	    button.click();
	  }-*/;

	/**
	 * Programmatic equivalent of the user clicking the button.
	 */
	public void click() {
		click(getElement());
	}
}
